﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Flow_MoveUpStep_V2]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Flow_MoveUpStep_V2];
GO
CREATE PROCEDURE [dbo].[sproc_Flow_MoveUpStep_V2]
    @FlowID int,
    @StepID int
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;

IF @StepID > 1 
BEGIN
    -- start a new transaction
    BEGIN TRANSACTION;

    UPDATE dbo.UDS_Flow_Step SET Step_ID = -1 WHERE Flow_ID = @FlowID and Step_ID = @StepID - 1

    UPDATE dbo.UDS_Flow_Step SET Step_ID = Step_ID -1 WHERE Flow_ID = @FlowID and Step_ID = @StepID

    UPDATE dbo.UDS_Flow_Step SET Step_ID = @StepID WHERE Flow_ID = @FlowID and Step_ID = -1

    -- commit the transaction
    COMMIT TRANSACTION;

    RETURN 0;
END
ELSE
    RETURN 1;

END
GO